package leetcode_core.leetcode_1;

import java.util.Arrays;
import java.util.Comparator;

public class FindMinArrowShots {
    public int findMinArrowShots(int[][] points) {
        if(points.length == 0){
            return 0;
        }
        int count = 1;
        //默认射出了第一支箭,这只箭射向的是end最小的元素
        Arrays.sort(points, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if(o1[1] >o2[1]){
                    return 1;
                }else if(o1[1] == o2[1]){
                    return 0;
                }
                return -1;
            }
        });
        int xEnd = points[0][1];
        for (int[] point : points) {
            if(xEnd < point[0]){
                count++;
                xEnd = point[1];
            }
        }
        return count;
    }
}
